package com.spider.demo7tcp4;

import java.io.*;
import java.net.Socket;

public class ServerReader extends Thread implements Runnable{
    private Socket socket;
    public ServerReader(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        //负责读取管道的消息
            try {
                //给当前对应的浏览器管道响应一个网页数据回去。
                OutputStream os = socket.getOutputStream();
                //通过字节输出流包装写出去数据给浏览器
                PrintStream ps = new PrintStream(os);
                ps.println("HTTP/1.1 200 OK");
                ps.println("Content-Type:text/html;charset=utf-8");
                ps.println();
                ps.println("<html>");
                ps.println("<body>");
                ps.println("<h1>欢迎来到Spider的博客</h1>");
                ps.println("</body>");
                ps.println("</html>");
                ps.close();
                socket.close();

            } catch (Exception e) {
                System.out.println("客户端"+ socket.getInetAddress().getHostAddress()+"已退出");
            }

    }
}
